<?php

declare (strict_types = 1);

namespace app\controller\admin\system\permission;

use app\BaseController;
use app\service\admin\system\DeptService;

class Dept extends BaseController
{
    protected $deptService;

    public function initialize()
    {
        $this->deptService = make(DeptService::class);
    }
    /**
     * 部门列表tree
     */
    public function getList()
    {
        $param = $this->request->get();
        return $this->success($this->deptService->getList($param));
    }
    /**
     * 部门编辑
     */
    public function edit()
    {
        $data = $this->request->post();
        $this->validate($data, [
            'name' => 'require|length:2,20',
            'status' => 'integer|in:0,1',
            'sort' => 'integer|egt:1|elt:255',
        ]);
        return $this->deptService->edit($data, (int) $data['id']) ? $this->success() : $this->error('保存失败');
    }
    /**
     * 部门删除
     */
    public function delete(int $dept_id)
    {
        return $this->deptService->delete($dept_id) ? $this->success() : $this->error('保存失败');
    }
}
